package com.google.code.virtualhockey.vhx.server.model

import com.google.code.virtualhockey.vhx.sds.fields._
import com.google.code.virtualhockey.vhx.sds.{STNumberedEntity, STMetaData}
import java.util.Date

/**
 * Represents a single game season.
 */
class Season( cpId: Option[Long],
              val name: String,
              var startDate: Option[Date],
              var endDate: Option[Date] ) extends STNumberedEntity[Season] {

  setEntityId( cpId )

  /** Private no-arg constructor for SDS. */
  private def this() = this( None, null, None, None )
}

object SeasonMeta extends STMetaData[Season] {
  val cls = classOf[Season]
  val kind = "Season"
  val fields = List(
    new SShortText( this, "name", false ),
    new SDate( this, "startDate", false ),
    new SDate( this, "endDate", false ) )

  /**
   * Creates a new Season instance from a CSV file line.
   */
  override def fromCsv( values: List[Any] ): Season = {
    new Season( getOptionalCsvValue( values(0) ),
                values(1).toString,
                getOptionalCsvValue( values(2) ),
                getOptionalCsvValue( values(3) ) )
  }
}
